<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>void try_throw_std_exception_from_error(std::error_code ec, const std::string &amp;msg = std::string{}) - Boost.Outcome documentation</title>
<link rel="stylesheet" href="../../css/boost.css" type="text/css">
<meta name="generator" content="Hugo 0.52 with Boostdoc theme">
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>

<link rel="icon" href="../../images/favicon.ico" type="image/ico"/>
<body><div class="spirit-nav">
<a accesskey="p" href="../../reference/functions/strong_swap.html"><img src="../../images/prev.png" alt="Prev"></a>
    <a accesskey="u" href="../../reference/functions.html"><img src="../../images/up.png" alt="Up"></a>
    <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../faq.html"><img src="../../images/next.png" alt="Next"></a></div><div id="content">
  <div class="titlepage"><div><div><h1 style="clear: both"><code>void try_throw_std_exception_from_error(std::error_code ec, const std::string &amp;msg = std::string{})</code></h1></div></div></div>
  <p>This function saves writing boilerplate by throwing a standard library exception
type equivalent to the supplied error code, with an optional custom message.</p>

<p>If the function returns, there is no standard library exception type equivalent
to the supplied error code. The following codes produce the following exception
throws:</p>

<dl>
<dt><code>EINVAL</code>
<dd><code>std::invalid_argument</code>
<dt><code>EDOM</code>
<dd><code>std::domain_error</code>
<dt><code>E2BIG</code>
<dd><code>std::length_error</code>
<dt><code>ERANGE</code>
<dd><code>std::out_of_range</code>
<dt><code>EOVERFLOW</code>
<dd><code>std::overflow_error</code>
<dt><code>ENOMEM</code>
<dd><code>std::bad_alloc</code>
</dl>

<p>The choice to refer to POSIX <code>errno</code> values above reflects the matching algorithm.
As 
<a href="https://en.cppreference.com/w/cpp/error/errc" class="api-reference" target="_blank"><i class="fa fa-book" aria-hidden="true"></i> <code>std::errc</code></a>
 exactly maps POSIX <code>errno</code>, on all platforms

<a href="https://en.cppreference.com/w/cpp/error/generic_category" class="api-reference" target="_blank"><i class="fa fa-book" aria-hidden="true"></i> <code>std::generic_category</code></a>
 error codes are matched by this function.
Only on POSIX platforms only are 
<a href="https://en.cppreference.com/w/cpp/error/system_category" class="api-reference" target="_blank"><i class="fa fa-book" aria-hidden="true"></i> <code>std::system_category</code></a>
 error codes
also matched by this function.</p>

<p><em>Overridable</em>: Not overridable.</p>

<p><em>Requires</em>: C++ exceptions to be globally enabled.</p>

<p><em>Namespace</em>: <code>BOOST_OUTCOME_V2_NAMESPACE</code></p>

<p><em>Header</em>: <code>&lt;boost/outcome/utils.hpp&gt;</code></p>


        </div><p><small>Last revised: February 01, 2019 at 23:42:52 UTC</small></p>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../../reference/functions/strong_swap.html"><img src="../../images/prev.png" alt="Prev"></a>
    <a accesskey="u" href="../../reference/functions.html"><img src="../../images/up.png" alt="Up"></a>
    <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../faq.html"><img src="../../images/next.png" alt="Next"></a></div></body>
</html>
